<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>输入法触发mouseLeave问题</title>
    <style>
      .box {
        display: none;
        background-color: aquamarine;
        width: 500px;
        height: 500px;
      }
    </style>
    <link rel="stylesheet" href="test.css" />
  </head>
  <body>
    <button id="hover-btn">hover</button>
    <div id="content-box" class="box"><input id="input" type="text" name="" id="" /></div>
    <span>sdkljfkljasdklfjskljfklsj</span>
    <script>
      const btn = document.getElementById("hover-btn");
      const box = document.getElementById("content-box");
      const input = document.getElementById("input");
      let isInput = false;

      btn.addEventListener("mouseenter", () => {
        box.style.display = "block";
      });
      box.addEventListener("mouseleave", () => {
        isInput ? "" : (box.style.display = "none");
      });
      input.addEventListener("compositionstart", () => {
        isInput = true;
      });
      input.addEventListener("compositionend", () => {
        isInput = false;
      });
    </script>
  </body>
</html>
